package net.dntuan.training.spring.integration;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author tuan.dangnhu
 * 
 * $LastChangedRevision: 123 $
 * $LastChangedDate: 2014-10-06 03:19:46 +0000 (Mon, 06 Oct 2014) $
 * $LastChangedBy: dnhutuan@gmail.com $
 */
public class MessageServiceActivator {

  private static final Logger LOGGER = LoggerFactory.getLogger(MessageServiceActivator.class);

  @Autowired
  BusinessService businessService;

  /**
   * just make content uppercase
   * @param req
   * @return
   */
  public Result receive(Message req) {
    LOGGER.info("content: " + req.getContent());
    businessService.doSomething();
    Result result = new Result();
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss");
    result.setNow(sdf.format(new Date()));
    result.setSpent(System.currentTimeMillis() - req.getStartTime());
    result.setContent(req.getContent().toUpperCase());
    return result;
  }
}
